package gupao.concurrency.simpledemo.simulate;

import gupao.concurrency.simpledemo.model.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class UserInfoMockService {
    private Map<String, UserInfo> userInfoMockMap = new HashMap<>();

    @PostConstruct
    public void init(){
        userInfoMockMap.put("0000", new UserInfo("0000","138-****-0000","xxx 路 0000 号"));
        userInfoMockMap.put("0001", new UserInfo("0001","138-****-0001","xxx 路 0001 号"));
        userInfoMockMap.put("0002", new UserInfo("0002","138-****-0002","xxx 路 0002 号"));
        userInfoMockMap.put("0003", new UserInfo("0003","138-****-0003","xxx 路 0003 号"));
        userInfoMockMap.put("0004", new UserInfo("0004","138-****-0004","xxx 路 0004 号"));
        userInfoMockMap.put("0005", new UserInfo("0005","138-****-0005","xxx 路 0005 号"));
        userInfoMockMap.put("0006", new UserInfo("0006","138-****-0006","xxx 路 0006 号"));
        userInfoMockMap.put("0007", new UserInfo("0007","138-****-0007","xxx 路 0007 号"));
        userInfoMockMap.put("0008", new UserInfo("0008","138-****-0008","xxx 路 0008 号"));
        userInfoMockMap.put("0009", new UserInfo("0009","138-****-0009","xxx 路 0009 号"));
    }


    public UserInfo queryUserInfo(String uid){
        TimeCostMock.mockTimeCost((int)(Math.random() * 300) + 1);
        return uid == null ? null : userInfoMockMap.get(uid);
    }

}
